ockam_macros 0.15.0

End-to-end encryption and mutual authentication for distributed applications.
Documentation

ockam_macros

crate docs license discuss

Ockam is a library for building devices that communicate securely, privately and trustfully with cloud services and other devices.

This crate provides shared macros.

Usage

Add this to your Cargo.toml:

[dependencies]
ockam_macros = "0.15.0"

All macros except for those used exclusively for testing purposes are re-exported by the ockam crate, so you may see examples where the macros are exported from ockam_macros if are related to tests or from ockam in any other case.

You can read more about how to use the macros and the supported attributes by each of them in the crate documentation.

AsyncTryClone

Implements the AsyncTryClone trait as defined in ockam_core::AsyncTryClone.

#[derive(ockam::AsyncTryClone)]
pub struct MyStruct {
    a: u32,
}

Message

Implements the Message trait as defined in ockam_core::Message.

#[derive(ockam::Message, Deserialize, Serialize)]
pub struct MyStruct {
    a: u32,
}

Node

Transforms the main function into an async function that sets up a node and provides a Context to interact with it.

#[ockam::node]
async fn main(mut ctx: ockam::Context) -> ockam::Result<()> {
    // ...
}

If you are executing your code in a no_std platform that doesn't support a main entry point, you must use the no_main attribute:

#[ockam::node(no_main)]
async fn main(mut ctx: ockam::Context) -> ockam::Result<()> {
    // ...
}

Tests

To write node-related tests:

#[ockam::test]
async fn main(mut ctx: ockam::Context) -> ockam::Result<()> {
    // ...
}

To write vault-related tests:

use ockam_vault::Vault;

fn new_vault() -> Vault {
    Vault::default()
}

#[ockam_macros::vault_test]
fn hkdf() {}

Develop

Due to dependencies constraints, the tests for all the macros contained in this crate are located in the ockam crate.

To test changes done in any of the macros you can use the macro_expand_playground from the ockam crate to see how a macro expands a given input.

License

This code is licensed under the terms of the Apache License 2.0.